#include "ttank.h"
#include "game.h"

void TTank::move(){
    switch(this->getState()){
    case UP:
        _velocity.x(0);
        _velocity.y(-5);
        break;
    case DOWN:
        _velocity.x(0);
        _velocity.y(5);
        break;
    case RIGHT:
        _velocity.x(5);
        _velocity.y(0);
        break;
    case LEFT:
        _velocity.x(-5);
        _velocity.y(0);
        break;
    case SHOOT:
        TObject* bullet = Game::Instance()->createObject('b');
        bullet -> setPosition(_velocity.normal()*(_size.abs() + bullet->getSize().abs())/2 + _position);
        bullet -> setVelocity(_velocity*2.5);
        _state = _state.previous();
    }

    _position += _velocity;
}

TTank::TTank()
    : TObject(new TGraphic(this,true))
{
    _type  = 't';
    _state = 0;
    _size.x(100);
    _size.y(50);
    this->getGraphic()->bindImageWithState(UP,":/eg/up");
    this->getGraphic()->bindImageWithState(DOWN,":/eg/down");
    this->getGraphic()->bindImageWithState(RIGHT,":/eg/right");
    this->getGraphic()->bindImageWithState(LEFT,":/eg/left");
}
